package com.tjec.project.businessStandardLibrary.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.tjec.common.utils.DateUtils;
import com.tjec.common.utils.StringUtils;
import com.tjec.project.system.mapper.BmsMdAreaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tjec.project.businessStandardLibrary.mapper.BmsKnowledgePoliciesMapper;
import com.tjec.project.businessStandardLibrary.domain.BmsKnowledgePolicies;
import com.tjec.project.businessStandardLibrary.service.IBmsKnowledgePoliciesService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 法规导航Service业务层处理
 * 
 * @author pangyognfeng
 * @date 2020-04-21
 */
@Service
public class BmsKnowledgePoliciesServiceImpl implements IBmsKnowledgePoliciesService 
{
    @Autowired
    private BmsKnowledgePoliciesMapper bmsKnowledgePoliciesMapper;
    @Autowired
    private BmsMdAreaMapper bmsMdAreaMapper;
    /**
     * 查询法规导航
     * 
     * @param guid 法规导航ID
     * @return 法规导航
     */
    @Override
    public BmsKnowledgePolicies selectBmsKnowledgePoliciesByGuid(String guid)
    {

        BmsKnowledgePolicies  bmsKnowledgePolicies = bmsKnowledgePoliciesMapper.selectBmsKnowledgePoliciesByGuid(guid);
        /*String proviceName=bmsKnowledgePolicies.getProvince();
        String cityName=bmsKnowledgePolicies.getCity();
        ArrayList cityIds= new ArrayList<String>();
        if(StringUtils.isNotBlank(proviceName)&&StringUtils.isNotBlank(cityName)){
            cityIds.add(bmsMdAreaMapper.selectBmsMdAreaByName(proviceName,1).getGuid());
            cityIds.add(bmsMdAreaMapper.selectBmsMdAreaByName(cityName,2).getGuid());
        }
        bmsKnowledgePolicies.setCitys(cityIds);
*/
        return bmsKnowledgePolicies;
    }

    /**
     * 查询法规导航列表
     * 
     * @param bmsKnowledgePolicies 法规导航
     * @return 法规导航
     */
    @Override
    public List<BmsKnowledgePolicies> selectBmsKnowledgePoliciesList(BmsKnowledgePolicies bmsKnowledgePolicies)
    {
/*
       String city= bmsKnowledgePolicies.getCity();
        if(city==null||city.equals("")){

        }else {
        bmsKnowledgePolicies.setProvince(bmsMdAreaMapper.selectBmsMdAreaByGuid(bmsKnowledgePolicies.getProvince()).getCname());
        bmsKnowledgePolicies.setCity(bmsMdAreaMapper.selectBmsMdAreaByGuid(bmsKnowledgePolicies.getCity()).getCname());
        }*/
        List<BmsKnowledgePolicies> lists=bmsKnowledgePoliciesMapper.selectBmsKnowledgePoliciesList(bmsKnowledgePolicies);

       return lists;
    }

    /**
     * 新增法规导航
     * 
     * @param bmsKnowledgePolicies 法规导航
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertBmsKnowledgePolicies(BmsKnowledgePolicies bmsKnowledgePolicies)
    {
       /* bmsKnowledgePolicies.setCreateTime(DateUtils.getNowDate());
        List<String>  lists= bmsKnowledgePolicies.getCitys();
        if(lists==null||lists.equals("")||lists.isEmpty()){

        }else {
            bmsKnowledgePolicies.setProvince(bmsMdAreaMapper.selectBmsMdAreaByGuid(lists.get(0)).getCname());
            bmsKnowledgePolicies.setCity(bmsMdAreaMapper.selectBmsMdAreaByGuid(lists.get(1)).getCname());
        }*/
        return bmsKnowledgePoliciesMapper.insertBmsKnowledgePolicies(bmsKnowledgePolicies);
    }

    /**
     * 修改法规导航
     * 
     * @param bmsKnowledgePolicies 法规导航
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateBmsKnowledgePolicies(BmsKnowledgePolicies bmsKnowledgePolicies)
    {
        /*List<String>  lists= bmsKnowledgePolicies.getCitys();
        if(lists==null||lists.equals("")||lists.isEmpty()){

        }else {
            bmsKnowledgePolicies.setProvince(bmsMdAreaMapper.selectBmsMdAreaByGuid(lists.get(0)).getCname());
            bmsKnowledgePolicies.setCity(bmsMdAreaMapper.selectBmsMdAreaByGuid(lists.get(1)).getCname());
        }*/
        bmsKnowledgePolicies.setUpdateTime(DateUtils.getNowDate());
        return bmsKnowledgePoliciesMapper.updateBmsKnowledgePolicies(bmsKnowledgePolicies);
    }

    /**
     * 批量删除法规导航
     * 
     * @param guids 需要删除的法规导航ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteBmsKnowledgePoliciesByGuids(String[] guids)
    {
        return bmsKnowledgePoliciesMapper.deleteBmsKnowledgePoliciesByGuids(guids);
    }

    /**
     * 删除法规导航信息
     * 
     * @param guid 法规导航ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteBmsKnowledgePoliciesByGuid(String guid)
    {
        return bmsKnowledgePoliciesMapper.deleteBmsKnowledgePoliciesByGuid(guid);
    }
}
